package main

func main() {

	l5 := ListNode{
		Val:  3,
		Next: nil,
	}

	l4 := ListNode{
		Val:  3,
		Next: &l5,
	}
	l3 := ListNode{
		Val:  2,
		Next: &l4,
	}

	l2 := ListNode{
		Val:  1,
		Next: &l3,
	}

	l1 := ListNode{
		Val:  1,
		Next: &l2,
	}

	PrintList(&l1)
	r := deleteDuplicates(&l1)
	PrintList(r)

}

func deleteDuplicates(head *ListNode) *ListNode {

	if head == nil {
		return nil
	}

	// 相当于copy一份，用于计算
	cur := head
	for cur.Next != nil {
		if cur.Val == cur.Next.Val {
			cur.Next = cur.Next.Next
		} else {
			cur = cur.Next
		}
	}
	return head
}

type ListNode struct {
	Val  int
	Next *ListNode
}

func PrintList(l *ListNode) {

	for l != nil {
		print(l.Val, " ")
		l = l.Next
	}

	println("")
}
